from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from apps.goods.models import SKUImage, SKU


# 获取图片列表序列化器
class ImageSerializer(ModelSerializer):
    # 返回图片关联的sku的id值
    sku = serializers.PrimaryKeyRelatedField(read_only=True)

    class Meta:
        model = SKUImage
        fields = "__all__"


# 保存图片序列化器
class SKUSerializer(ModelSerializer):
    class Meta:
        model = SKU
        fields = ('id', 'name')
